package com.spring.common.web.controller;

import java.util.List;
import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import org.apache.commons.lang3.StringUtils;
import org.codehaus.jackson.map.util.JSONPObject;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import com.google.common.collect.Maps;
import com.spera.shopoa.util.ShopOaSessionUtil;
import com.spera.shopoa.util.ShopOaSessionUtil.OaUser;
import com.spring.common.web.service.CommonSelService;
import com.spring.security.core.util.ApplicationUtils;

/**
 * 通用下拉
 * @author wojunyu
 *
 */
@Controller
@RequestMapping(value = "/commonSel")
public class CommonSelController {
	
	@Resource
	private CommonSelService commonSelService;
	
	@RequestMapping(value = "/queryCustomer")
    public ModelAndView queryCustomer(HttpServletRequest request){
		return new ModelAndView("main/commonsel/querycustomer");
    }
	
	/**
	 * 乐园下拉
	 * @return
	 */
	@RequestMapping(value = "/getParkSel")
	@ResponseBody
	public Object getParkSel() {
		List<Map<String, Object>> m = null;
		try {
			m = commonSelService.getParkSel(null);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return m;
	}
	
	/**
	 * 获取OA下级部门接口
	 * @param callback
	 * @return
	 */
	@RequestMapping(value = "/queryDepartmentPark")
	@ResponseBody
	public Object queryDepartmentPark(String dept_id,String callback) {
		List<Map<String, Object>> m = commonSelService.queryDepartmentPark(dept_id);
		if (ApplicationUtils.isNotNull(callback)) {
			return new JSONPObject(callback, m);
		} else {
			return m;
		}
	}


	/**
	 * 获取OA下级部门及人员接口
	 * @param callback
	 * @return
	 */
	@RequestMapping(value = "/easyTreeDeptUser")
	@ResponseBody
	public Object easyTreeDeptUser(String dept_id,String callback) {
		List<Map<String, Object>> m = commonSelService.easyTreeDeptUser(dept_id);
		if (ApplicationUtils.isNotNull(callback)) {
			return new JSONPObject(callback, m);
		} else {
			return m;
		}
	}

	/**
	 * 获取OA下级部门接口
	 * @param callback
	 * @return
	 */
	@RequestMapping(value = "/easyTreeDept")
	@ResponseBody
	public Object easyTreeDept(String dept_id,String callback) {
		List<Map<String, Object>> m = commonSelService.easyTreeDept(dept_id);
		if (ApplicationUtils.isNotNull(callback)) {
			return new JSONPObject(callback, m);
		} else {
			return m;
		}
	}

	/**
	 * 根据部门编号获取部门下面的用户
	 * @param callback
	 * priv_id:kewubu
	 * shopDeptId:门店编号
	 * dept_id:部门编号
	 * @return
	 */
	@RequestMapping(value = "/queryUserByDeptId")
	@ResponseBody
	public Object queryUserByDeptId(String dept_id,String shopDeptId,String priv_id,String callback) {
		List<Map<String, Object>> m = commonSelService.queryUserByDeptId(dept_id,shopDeptId,priv_id);
		if (ApplicationUtils.isNotNull(callback)) {
			return new JSONPObject(callback, m);
		} else {
			return m;
		}
	}
	
	/**
	 * 排班类型下拉
	 * @param c_user_id
	 * @param request
	 * @return
	 */
	@RequestMapping(value = "/getScheduleType")
    @ResponseBody
    public Object getScheduleType(HttpServletRequest request){
		List<Map<String, Object>> scheduleList = commonSelService.getScheduleType();
        return scheduleList;
    }
	
	/**
	 * 教学大纲下拉
	 * @param request
	 * @return
	 */
	@RequestMapping(value = "/getCourseOutLook")
    @ResponseBody
    public Object getCourseOutLook(HttpServletRequest request){
		OaUser oaUser = ShopOaSessionUtil.getOaUser(request);
		if(StringUtils.isEmpty(oaUser.getKids_park_id())){
			return null;
		}
		Map<String,Object> m = Maps.newHashMap();
		m.put("kids_parkID", oaUser.getKids_park_id());
		List<Map<String, Object>> courseOutLookList = commonSelService.getCourseOutLook(m);
        return courseOutLookList;
    }
	
	/**
	 * 教室下拉
	 * @param request
	 * @return
	 */
	@RequestMapping(value = "/getClassRoom")
    @ResponseBody
    public Object getClassRoom(HttpServletRequest request){
		OaUser oaUser = ShopOaSessionUtil.getOaUser(request);
		if(StringUtils.isEmpty(oaUser.getKids_park_id())){
			return null;
		}
		Map<String,Object> m = Maps.newHashMap();
		m.put("kids_parkID", oaUser.getKids_park_id());
		List<Map<String, Object>> classRoomList = commonSelService.getClassRoom(m);
        return classRoomList;
    }
	
	/**
	 * 乐园课程下拉(查询的时course表，顺带courseType字段)
	 * @param request
	 * @return
	 */
	@RequestMapping(value = "/getKidsParkCourse")
    @ResponseBody
    public Object getKidsParkCourse(HttpServletRequest request){
		OaUser oaUser = ShopOaSessionUtil.getOaUser(request);
		if(StringUtils.isEmpty(oaUser.getKids_park_id())){
			return null;
		}
		Map<String,Object> m = Maps.newHashMap();
		m.put("kids_parkID", oaUser.getKids_park_id());
		List<Map<String, Object>> kidsParkCourseList = commonSelService.getKidsParkCourse(m);
        return kidsParkCourseList;
    }
	
	/**
	 * 查询报表下拉
	 * @param type
	 * @param request
	 * @return
	 */
	@RequestMapping(value = "/getReportSel")
    @ResponseBody
    public Object getReportSel(String type,HttpServletRequest request){
		List<Map<String, Object>> reportList = commonSelService.getReportSel(type);
        return reportList;
    }
	
	/**
	 * 教室下拉
	 * @param request
	 * @return
	 */
	@RequestMapping(value = "/signProductSel")
    @ResponseBody
    public Object signProductSel(HttpServletRequest request){
//		OaUser oaUser = ShopOaSessionUtil.getOaUser(request);
//		if(StringUtils.isEmpty(oaUser.getKids_park_id())){
//			return null;
//		}
		Map<String,Object> m = Maps.newHashMap();
		List<Map<String, Object>> signProductList = commonSelService.signProductSel(m);
        return signProductList;
    }
	
	/**
	 * 客户下拉
	 * @param request
	 * @return
	 */
	@RequestMapping(value = "/getCustomerSel")
    @ResponseBody
    public Object getCustomerSel(HttpServletRequest request){
		Map<String,Object> m = Maps.newHashMap();
		List<Map<String, Object>> dataList = commonSelService.getCustomerSel(m);
        return dataList;
    }
	
	/**
	 * 客户的联系人下拉
	 * @param request
	 * @return
	 */
	@RequestMapping(value = "/getContactSel")
    @ResponseBody
    public Object getContactSel(@RequestParam String customerId,HttpServletRequest request){
		Map<String,Object> m = Maps.newHashMap();
		List<Map<String, Object>> dataList = commonSelService.getContactSel(m);
        return dataList;
    }
	
}
